package logic

import (
	"context"
	"goods_srv/models/mysql"

	"goods_srv/goodssrv"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *goodssrv.OrderListRequest) (*goodssrv.OrderListResponse, error) {
	var orders []mysql.Order
	mysql.DB.Debug().Find(&orders)

	var orderList []*goodssrv.OrderList
	for _, v := range orders {
		orderList = append(orderList, &goodssrv.OrderList{
			OrderId:   int64(v.ID),
			UserId:    int64(v.UserId),
			Numbering: v.Numbering,
			Total:     float32(v.Total),
			PayTypes:  v.PayTypes,
			Status:    v.Status,
		})
	}
	return &goodssrv.OrderListResponse{
		List: orderList,
	}, nil
}
